/**
 * @Author: Your name
 * @Date:   2021-10-12 17:43:40
 * @Last Modified by:   Your name
 * @Last Modified time: 2021-10-12 20:58:29
 */
(function () {
    let arrlist = [];
    $.ajax({
        url: 'http://chst.vip:1234/api/getcategorytitle'
    }).then(res => {
        data = res.result;
        data.forEach(item => {
            let obj = {};
            obj.titleid = item.titleId;
            obj.title = item.title;
            arrlist.push(obj);
        })
        let html = arrlist.reduce((value, item, index) => {
            return value +
                `
                <li class="title">
                    <div class="title-heading">
                        <h4>
                        <span>${item.title}</span>
                        <i>▼</i>
                        </h4>
                    </div>
                    <div class="container">
                        <ul class="categoryList"></ul>
                    </div>
                </li>
            `
        }, "")
        $("main .title-group").html(html)
        var as = $(".title").find("h4");
        var categoryList = document.querySelectorAll(".categoryList");
        var arr = [];
        for (var i = 0; i < as.length; i++) {
            var tid = i;
            $.ajax({
                url: "http://chst.vip:1234/api/getcategory",
                data: {
                    titleid: tid
                }
            }).then(res => {
                data = res.result;
                // console.log(data);
                let html = "";
                data.forEach(item => {
    
                    html += `
                        <li>
                            <a href="../pages/categoryshoplist.html?title=${item.category}&categoryid=${item.categoryId}" categoryid="${item.categoryId}" title="${item.category}">${item.category}</a>
                        </li> 
                    `
                })
                arr.push(html);
                for (var j = 0; j < arr.length; j++) {
                    categoryList[j].innerHTML = arr[j];
                }
                $(".categoryList li").on("click","a",function(){
                    let categoryid=$(this).attr("categoryid");
                    let title=$(this).attr("title")
                    location.href=`bijia.html?title=${title}&categoryid=${categoryid}`;
                })
            })

        }
        $(".categoryList").slideUp(13);
        $(".title-heading").click(function () {
            $(this).parent().find(".categoryList").slideToggle(300).parent().parent().siblings().find(".categoryList").slideUp(300);
        })
    })

})()